from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

opt = Options()
# 添加detach选项，使浏览器在脚本执行完毕后继续运行
opt.add_experimental_option('detach', True)
browser = webdriver.Chrome(options=opt)

url = 'https://www.baidu.com'
browser.get(url)

time.sleep(2)
srk = browser.find_element(By.ID,"kw")
srk.send_keys('mysql')

time.sleep(2)
button= browser.find_element(By.ID,"su")
button.click()

time.sleep(2)

#滑到底部
js_bottom = 'document.documentElement.scrollTop=100000'
browser.execute_script(js_bottom)

time.sleep(2)

next_page = browser.find_element(By.XPATH,'//a[@class="n "]')
next_page.click()

time.sleep(2)

# 回到上一页
browser.back()

time.sleep(2)

browser.forward()

time.sleep(4)

browser.quit()
